package com.furongji.education.config;

import com.furongji.common.utils.UserThreadLocalUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfiguration {

    @Bean
    public RequestInterceptor userInfoRequestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                String userInfo = UserThreadLocalUtil.getUser();
                if (userInfo == null) {
                    return;
                }
                template.header("user-info", userInfo);
            }
        };
    }
}
